<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
       <el-form-item label="姓名" prop="userName">
        <el-input
          v-model="queryParams.userName"
          placeholder="请输入姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="员工编号" prop="userNo">
        <el-input
          v-model="queryParams.userNo"
          placeholder="请输入员工编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="系统名称" prop="systemName">
        <el-select
              v-model="queryParams.systemName"
              placeholder="请选择系统名称"
              clearable
              size="small"
            >
              <el-option
                v-for="dict in systemOptions"
                :key="dict.sysNum"
                :label="dict.sysName"
                :value="dict.sysNum"
              />
            </el-select>
      </el-form-item>
      <el-form-item label="账号" prop="account">
        <el-input
          v-model="queryParams.account"
          placeholder="请输入账号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注" prop="remark">
        <el-input
          v-model="queryParams.remark"
          placeholder="请输入备注"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!--<el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:account:export']"
        >导出</el-button>
      </el-col>-->
	  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="accountList" :default-sort="{ prop: 'createTime', order: 'descending' }"
      @sort-change="tableSortChange">
      <el-table-column label="姓名" align="center" prop="userName"  :sort-orders="['ascending', 'descending']"
        sortable="custom"/>
      <el-table-column label="员工编号" align="center" prop="userNo"  :sort-orders="['ascending', 'descending']"
        sortable="custom"/>
      <el-table-column label="系统名称" align="center" prop="systemName" :formatter="systemNameFormatter"/>
      <el-table-column label="账号" align="center" prop="account"  :sort-orders="['ascending', 'descending']"
        sortable="custom"/>
      <el-table-column label="备注" align="center" prop="remark"  :sort-orders="['ascending', 'descending']"
        sortable="custom"/>
      <el-table-column label="账号状态" align="center" prop="userStatus" :formatter="userStatusFormatter"/>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listAccount,exportAccount } from "@/api/system/holderAccount";
import { getSystemDict } from "@/api/system/sysList";
export default {
  name: "holderAccount",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      accountList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        systemName: null,
        account: null,
        userId: null,
        userName:null,
        remark:null,
        userNo:null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      systemOptions:[],
      portalStatusOptions:[]
    };
  },
  created() {
    this.getDicts("sys_user_status").then((response) => {
      this.portalStatusOptions = response.data;
    });
    //this.getSystemOptions();
    //this.getList();

    this.sortFun();
  },
  methods: {
    sortFun(){
      Promise.all([
        this.getSystemOptions(),
        this.getList()
    ]);
    },
    userStatusFormatter(row, column){
      var userStatus = "";
      if(row.systemName==="portal"){
        return this.selectDictLabel(this.portalStatusOptions, row.userStatus);
      }else if(row.systemName==="OA"){
        if(row.userStatus && row.userStatus==="0"){
          userStatus = "禁用";
        }else  if(row.userStatus && row.userStatus==="1"){
          userStatus = "启用";
        }else{
          userStatus = "休眠";
        }
      }else if(row.systemName==="JY" || row.systemName==="BPM" || row.systemName==="LK" ){
        if(row.userStatus && row.userStatus==="1"){
          userStatus = "启用";
        }else  if(row.userStatus && row.userStatus==="0"){
          userStatus = "禁用";
        }
      }else if(row.systemName==="EC"){
        if(row.userStatus && row.userStatus==="1"){
          userStatus = "启用";
        }else  if(row.userStatus && row.userStatus==="2"){
          userStatus = "禁用";
        }else  if(row.userStatus && row.userStatus==="3"){
          userStatus = "未启用";
        }
      }else{
        if(row.userStatus && row.userStatus==="1"){
          userStatus = "启用";
        }else{
          userStatus = "无";
        }
      }
      return userStatus;
    },
    systemNameFormatter(row, column){

      var actions = [];
      var datas = this.systemOptions,
          value = row.systemName;
      Object.keys(datas).some((key) => {
        if (datas[key].sysNum == ('' + value)) {
          actions.push(datas[key].sysName);
          return true;
        }
      })
      return actions.join('');
    },
    getSystemOptions(){
      return new Promise((resolve, reject) => {
        getSystemDict().then(res=>{
          this.systemOptions = res.data;
        });
      });
    },
    /** 查询【请填写功能名称】列表 */
    getList() {
      return new Promise((resolve, reject) => {
        this.loading = true;
        listAccount(this.queryParams).then(response => {
          this.accountList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有【请填写功能名称】数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportAccount(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    },tableSortChange(column) {
      this.queryParams.pageNum = 1;
      if (column.order === "descending") {
        this.queryParams.sortBy = column.prop;
        this.queryParams.order = "desc";
      } else {
        this.queryParams.sortBy = column.prop;
        this.queryParams.order = "asc";
      }
      this.getList();
    },
  }
};
</script>
